package net;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class InetAddressDemo {
    public static void main(String[] args) throws UnknownHostException {
        final InetAddress inetAddress1 = InetAddress.getByName("127.0.0.1");
        final InetAddress inetAddress2 = InetAddress.getByName("localhost");
        final InetAddress inetAddress3 = InetAddress.getLocalHost();
        System.out.println(inetAddress3);

        //查询网络ip地址
        final InetAddress inetAddress4 = InetAddress.getByName("www.baidu.com");
        System.out.println(inetAddress4);

        //常用方法
        //System.out.println(inetAddress4.getAddress());
        // 获得规范名字
        System.out.println(inetAddress4.getCanonicalHostName());
        //ip
        System.out.println(inetAddress4.getHostAddress());
        //域名，或者自己电脑的名字
        System.out.println(inetAddress4.getHostName());
    }
}
